package top.gelonggld.model;

import top.gelonggld.constants.PType;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gelon on 2017/5/27.
 */
public class ClassContent extends BaseParagraph {

    public List<Paragraph> paragraphs;

    public ClassContent(int start, int end, String paragraphStr, int type) {
        super(start, end, paragraphStr, type);
    }

    @Override
    public void onPushDate(String paragraphStr) {
        paragraphs = process(paragraphStr);
        Integer i = null ;
    }

    @Override
    public void initDate() {

    }


    private List<Paragraph> process(String classContent) {
        int begin = 0 ;
        int level = 0 ;
        boolean inStr = false ; //是否在字符串中
        List<Paragraph> paragraphs = new ArrayList<>();
        for (int i = 0 ; i < classContent.length(); i++ ){
            char ch = classContent.charAt(i);
            if(ch == '\"'){
                inStr = !inStr;
            }
//            if(noteNext && !inStr && ch)
            if(ch == ';' && level == 0 && !inStr){
                paragraphs.add(new Propty(begin + start,i+1+ start,classContent.substring(begin,i+1), PType.PROPETY));
                begin = i+1 ;
            }
            if(ch == '}' && !inStr){
                level -- ;
                if(level == 0){ //找到一个Method
                    paragraphs.add(new Method(begin + start,i+1+ start,classContent.substring(begin,i+1), PType.METHOD));
                    begin = i+1;
                }
            }
            if(ch == '{' && !inStr){
                level ++ ;
            }
        }
        return paragraphs;
    }
}
